ALMaSS  1.0
The Animal, Landscape and Man Simulation System
GeneticMaterial1616 Class Reference

#include <GeneticMaterial.h>

Public Member Functions

 GeneticMaterial1616 ()
 
void SetAllele (unsigned int locus, uint32 value, unsigned int Chromo)
 
uint32 GetAllele (unsigned int locus, unsigned int Chromo)
 
void PrintChromosome (char *C, unsigned int Chromosome)
 
void SetGeneticFlag ()
 
void SetDirectFlag ()
 
void UnsetGeneticFlag ()
 
void UnsetDirectFlag ()
 
uint32 GetGeneticFlag ()
 
uint32 GetDirectFlag ()
 
int HomozygosityCount ()
 
int HeterozygosityCount ()
 
void Recombine (GeneticMaterial1616 *Gene1, GeneticMaterial1616 *Gene2)
 
void Initiation (AlleleFreq1616 *Al)
 
void Mutation_1 ()
 
void Mutation_2 ()
 
void Mutation_3 ()
 

Protected Attributes

uint32 Chromosome [4]
 

Constructor & Destructor Documentation

◆ GeneticMaterial1616()

GeneticMaterial1616::GeneticMaterial1616 ( )
592  {
593  // ensure zeros in all loci
594  for ( int i = 0; i < 4; i++ ) Chromosome[ i ] = 0;
595 }
uint32 Chromosome[4]
Definition: GeneticMaterial.h:156

References Chromosome.

Member Function Documentation

◆ GetAllele()

uint32 GeneticMaterial1616::GetAllele ( unsigned int  locus,
unsigned int  Chromo 
)
599  {
600  // This is for 32 bit machines, 64bit is easier
601  // locus must be 0 to 15
602  //Chromo must be either 0 or 1
603  // These debug tests below are costly so turn off in release code
604  #ifdef __GENDEBUG
605  if (Chromo>1) {
606  g_msg->Warn( "Chromo > 1 in GeneticMaterial1616 - get allele", NULL );
607  exit( 0 );
608  }
609  if (locus>15) {
610  g_msg->Warn( "locus > 15 in GeneticMaterial1616 - get allele", NULL );
611  exit( 0 );
612  }
613  #endif
614 
615  uint32 segment=((Chromo<<1) | ((locus & 0x08)>>3)); // locates on which segment in the comosome we are in
616  uint32 allele=0x0F & (Chromosome[segment]>>((locus & 0x07)<<2)); //Locates the allele and shifts it down to the first postition to read
617  return allele;
618 }
unsigned int uint32
Definition: ALMaSS_Setup.h:34
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
class MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41

References Chromosome, g_msg, and MapErrorMsg::Warn().

Referenced by GetDirectFlag(), GetGeneticFlag(), HeterozygosityCount(), HomozygosityCount(), Mutation_2(), Mutation_3(), PrintChromosome(), and Recombine().

◆ GetDirectFlag()

uint32 GeneticMaterial1616::GetDirectFlag ( )
766  {
767  return GetAllele(0,1);
768 }
uint32 GetAllele(unsigned int locus, unsigned int Chromo)
Definition: GeneticMaterial.cpp:599

References GetAllele().

◆ GetGeneticFlag()

uint32 GeneticMaterial1616::GetGeneticFlag ( )
762  {
763  return GetAllele(0,0);
764 }

References GetAllele().

◆ HeterozygosityCount()

int GeneticMaterial1616::HeterozygosityCount ( )
718  {
719  int heterozyg = 0;
720  for ( int i = 0; i < 16; i++ ) {
721  if ( GetAllele( i, 0 ) != GetAllele( i, 1 ) ) heterozyg++;
722  }
723  return heterozyg;
724 }

References GetAllele().

◆ HomozygosityCount()

int GeneticMaterial1616::HomozygosityCount ( )
707  {
708  // OK OK there is an easy way to do this by calling HeterozygosityCount and
709  // subtracting this from 32, but just is case that little bit of saved time is useful:
710  int homozyg=0;
711  for ( int i = 0; i < 16; i++ ) {
712  if ( GetAllele( i, 0 ) == GetAllele( i, 1 ) ) homozyg++;
713  }
714  return homozyg;
715 }

References GetAllele().

◆ Initiation()

void GeneticMaterial1616::Initiation ( AlleleFreq1616 Al)

The method called to intialise genes on initiation of the simulation.
Gene frequencies are based on an external text file input read in on construction.

775  {
776  uint32 value; //, c;
777  for ( int l = 0; l < 16; l++ ) {
778  // if ( l < 16 ) c = 0; else c = 2;
779 
780  int chance = random( 1000 );
781  uint32 index = 0;
782  while ( chance >= Al->SupplyAN( l, index ) ) {
783  index++;
784  }
785  value = index;
786  // set the value
787  SetAllele( l, value, 0 );
788 
789  chance = random( 1000 );
790  index = 0;
791  while ( chance >= Al->SupplyAN( l, index ) ) {
792  index++;
793  }
794  value = index;
795  // set the value
796  SetAllele( l, value, 1 );
797  }
798 }
int random(int a_range)
Definition: ALMaSS_CmdLine.cpp:142
int SupplyAN(int loc, int al)
Definition: GeneticMaterial.h:135
void SetAllele(unsigned int locus, uint32 value, unsigned int Chromo)
Definition: GeneticMaterial.cpp:621

References random(), SetAllele(), and AlleleFreq1616::SupplyAN().

◆ Mutation_1()

void GeneticMaterial1616::Mutation_1 ( )

random allele choice

808 {
809  if (MutationChance != 0)
810  {
811  for ( int i = 0; i < 16; i++ )
812  {
813  if ( g_rand_uni() < MutationChance ) // one chance in Mutation Chance
814  {
815  SetAllele( i, random( 16 ), random( 2 ) );
816  }
817  }
818  }
819 }
double MutationChance
Definition: GeneticMaterial.cpp:52
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni

References g_rand_uni, MutationChance, random(), and SetAllele().

◆ Mutation_2()

void GeneticMaterial1616::Mutation_2 ( )

Move one allele + and 16 becomes 0

827 {
828  if (MutationChance != 0){
829  for ( int i = 0; i < 16; i++ ) {
830  if (g_rand_uni() < MutationChance) // one chance in Mutation Chance for the locus
831  {
832  unsigned int strand = random( 2 ); // kromosom 0 or 1
833  unsigned int allele = GetAllele( i, strand );
834  allele++;
835  allele&=0x0f; //and with 1111 - allels curls up 15 -> 0
836  SetAllele( i, allele, strand );
837  }
838  }
839 }
840 }

References g_rand_uni, GetAllele(), MutationChance, random(), and SetAllele().

◆ Mutation_3()

void GeneticMaterial1616::Mutation_3 ( )

Move one allele one up or down

848 {
849  if (MutationChance != 0){
850  for ( int i = 0; i < 16; i++ ) {
851  if ( g_rand_uni() < MutationChance) // one chance in Mutation Chance for the locus
852  {
853  unsigned strand = random( 2 ); // kromosom 0 or 1
854  unsigned allele = GetAllele( i, strand );
855  //if (strand == 1) allele++; else allele--;
856  if ( random( 2 ) == 1 ) allele++; else allele--;
857 
858  //For mutations less than 0 and more than 15 the mutation should result in 1 or 14
859 
860  if (allele > 0x0f) // Test to see if mutation to negative or above 15
861  {
862  allele |= 0x1C;
863  if(allele > 0x01C) { allele &= 0x01;}
864  else allele >>=1;
865  //allele|= 0xF0; // (240) Sets neg to 0, and 16 to 15 -> to avoid curling up
866  //allele = (~allele);
867  }
868 
869  SetAllele( i, allele, strand );
870  }
871  }
872 }
873 }

References g_rand_uni, GetAllele(), MutationChance, random(), and SetAllele().

◆ PrintChromosome()

void GeneticMaterial1616::PrintChromosome ( char *  C,
unsigned int  Chromosome 
)
649  {
650  for ( int i = 0; i < 16; i++ ) {
651  uint32 allele = GetAllele( i, Chromo );
652  switch ( allele ) {
653  case 0:
654  C[ i ] = 'a';
655  break;
656  case 1:
657  C[ i ] = 'b';
658  break;
659  case 2:
660  C[ i ] = 'c';
661  break;
662  case 3:
663  C[ i ] = 'd';
664  break;
665  case 4:
666  C[ i ] = 'e';
667  break;
668  case 5:
669  C[ i ] = 'f';
670  break;
671  case 6:
672  C[ i ] = 'g';
673  break;
674  case 7:
675  C[ i ] = 'h';
676  break;
677  case 8:
678  C[ i ] = 'i';
679  break;
680  case 9:
681  C[ i ] = 'j';
682  break;
683  case 10:
684  C[ i ] = 'k';
685  break;
686  case 11:
687  C[ i ] = 'l';
688  break;
689  case 12:
690  C[ i ] = 'm';
691  break;
692  case 13:
693  C[ i ] = 'n';
694  break;
695  case 14:
696  C[ i ] = 'o';
697  break;
698  case 15:
699  C[ i ] = 'p';
700  break;
701  }
702  }
703  C[ 16 ] = 0;
704 }

References GetAllele().

◆ Recombine()

void GeneticMaterial1616::Recombine ( GeneticMaterial1616 Gene1,
GeneticMaterial1616 Gene2 
)
727  {
728  // Is called with hers and his genes
729  for ( int i = 0; i < 16; i++ ) {
730  // For each locus
731  // Choose which chromosome for each parent
732  int g0 = random(2);
733  int g1 = random(2);
734  // get the two alleles
735  uint32 a0 = Gene1->GetAllele( i, g0 );
736  uint32 a1 = Gene2->GetAllele( i, g1 );
737  // put a0 into chromo0 & a1 to chromo1 & vice versa
738  SetAllele( i, a0, 0 );
739  SetAllele( i, a1, 1 );
740  }
741 }

References GetAllele(), random(), and SetAllele().

◆ SetAllele()

void GeneticMaterial1616::SetAllele ( unsigned int  locus,
uint32  value,
unsigned int  Chromo 
)
621  {
622  // This is for 32 bit machines, 64bit is easier
623  // locus must be 0 to 15
624  //Chromo must be either 0 or 1
625  // These debug tests below are costly so turn off in release code
626  #ifdef __GENDEBUG
627  if (Chromo>1) {
628  g_msg->Warn( "Chromo > 1 in GeneticMaterial1616 - set allele", NULL );
629  exit( 0 );
630  }
631  if (locus>15) {
632  g_msg->Warn( "locus > 15 in GeneticMaterial1616 - set allele", NULL );
633  exit( 0 );
634  }
635  #endif
636 
637  uint32 segment=((Chromo<<1) | ((locus & 0x08)>>3));
638  uint32 mask = 0x0F; //0000 1111F
639  // Need to shift the mask over the correct allele
640  mask=mask<<((locus&7)<<2);
641  value = value & 0x0f; // make sure there was no extra stuff added!
642  // create the value mask
643  value = value << ((locus&7)<<2);
644  Chromosome[ segment ] &= ~mask; // get rid of the current info
645  Chromosome[ segment ] |= value; // write the value
646 }

References Chromosome, g_msg, and MapErrorMsg::Warn().

Referenced by Initiation(), Mutation_1(), Mutation_2(), Mutation_3(), Recombine(), SetDirectFlag(), SetGeneticFlag(), UnsetDirectFlag(), and UnsetGeneticFlag().

◆ SetDirectFlag()

void GeneticMaterial1616::SetDirectFlag ( )
748  {
749  SetAllele(0,1,1);
750 }

References SetAllele().

◆ SetGeneticFlag()

void GeneticMaterial1616::SetGeneticFlag ( )
744  {
745  SetAllele(0,1,0);
746 }

References SetAllele().

◆ UnsetDirectFlag()

void GeneticMaterial1616::UnsetDirectFlag ( )
757  {
758  SetAllele(0,0,1);
759 }

References SetAllele().

◆ UnsetGeneticFlag()

void GeneticMaterial1616::UnsetGeneticFlag ( )
753  {
754  SetAllele(0,0,0);
755 }

References SetAllele().

Member Data Documentation

◆ Chromosome

uint32 GeneticMaterial1616::Chromosome[4]
protected

The documentation for this class was generated from the following files: